package com.mhl.adapter;

import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.mhl.campuscabinet.R;
import com.mhl.client.HttpUtil;

import java.util.List;

public class SellImageAdapter extends RecyclerView.Adapter<SellImageAdapter.MyViewHolder>{
    private final List<Bitmap> mSellImageList;
    //构造方法，传入数据
    public SellImageAdapter(List<Bitmap> list){
        this.mSellImageList = list;
    }

    @NonNull
    @Override
    public SellImageAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder，返回每一项的布局
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_sellimage, parent, false);
        return new SellImageAdapter.MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(SellImageAdapter.MyViewHolder holder, int position) {
        //将数据和控件绑定
//        holder.textView.setText(list.get(position));
        Bitmap bitmap = mSellImageList.get(position);

        //holder.productimage.setImageResource(ImageURL);
        //正式的获取图片是这个
        holder.sellimage.setImageBitmap(bitmap);


    }

    @Override
    public int getItemCount() {
        //返回Item总条数
        return mSellImageList.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView sellimage;
        public MyViewHolder(View itemView) {
            super(itemView);
            sellimage = (ImageView) itemView.findViewById(R.id.sellimage);
        }
    }
}
